@echo off
chcp 65001 >nul
echo ========================================
echo   一键部署并启动系统
echo ========================================
echo.

set PROJECT_DIR=%~dp0..
cd /d %PROJECT_DIR%

:: 1. 运行部署脚本
echo [1/4] 运行部署脚本...
call scripts\deploy_production_complete.bat
if %errorLevel% neq 0 (
    echo [错误] 部署失败，请检查错误信息
    pause
    exit /b 1
)

:: 2. 配置防火墙
echo.
echo [2/4] 配置防火墙...
net session >nul 2>&1
if %errorLevel% equ 0 (
    call scripts\configure_firewall.bat
) else (
    echo [提示] 需要管理员权限配置防火墙，请手动运行 scripts\configure_firewall.bat
)

:: 3. 获取IP地址
echo.
echo [3/4] 获取本机IP地址...
for /f "tokens=2 delims=:" %%a in ('ipconfig ^| findstr /C:"IPv4" ^| findstr /V "127.0.0.1"') do (
    set IP=%%a
    set IP=!IP: =!
    goto :found_ip
)
:found_ip

:: 4. 启动服务
echo.
echo [4/4] 启动服务...
call scripts\start_production.bat

echo.
echo ========================================
echo   ✅ 部署完成！
echo ========================================
echo.
echo 访问地址:
echo   本地访问:
echo     前端: http://localhost:8080
echo     API:  http://localhost:8000/api/
echo.
if defined IP (
    echo   局域网访问:
    echo     前端: http://%IP%:8080
    echo     API:  http://%IP%:8000/api/
    echo.
)
echo 管理后台: http://localhost:8000/admin/
echo.
echo 提示:
echo   - 确保MySQL服务正在运行
echo   - 确保防火墙已开放端口8080和8000
echo   - 如需公网访问，请使用内网穿透工具
echo.
pause

